# 将所有处理好的文件打包成ZIP
import io
import os
import zipfile

save_dir = r"/ACRmodel/static/dataset/番茄/4"
dataset_id = 4

zip_buffer = io.BytesIO()
with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zipf:
    for file in os.listdir(save_dir):
        file_path = os.path.join(save_dir, file)
        if os.path.isfile(file_path):  # 只打包文件，不打包子目录
            zipf.write(file_path, arcname=file)  # 保持文件名不变

# 保存ZIP文件
zip_filename = f"dataset_{dataset_id}.zip"
zip_path = os.path.join(save_dir, zip_filename)
with open(zip_path, 'wb') as f:
    f.write(zip_buffer.getvalue())
print(f"已生成压缩包: {zip_path}")
